// components/like/like.js
Component({
    /**
    * 组件的属性列表(可以被外部访问)
    */
    properties: {
        like: {
            type: Boolean,
        },
        count: {
            type: Number
        }
    },

    /**
    * 组件的初始数据(不能被外部访问)
    */
    data: {
        yesSrc: '../images/like.png',
        noSrc: '../images/like@dis.png',
    },
    attached(){
        // console.log(this.data);
    },

    /**
    * 组件的方法列表
    */
    methods: {
        onLike(e){
            let like = this.properties.like;
            let count = this.properties.count;
            like = !like;
            count = like ? count + 1 : count - 1;
            this.setData({
                like: like,
                count: count
            });
            //派发一个自定义事件
            let behavior = this.properties.like ? 'like' : 'unlike';
            this.triggerEvent('like', {
                behavior: behavior
            }, {});
        },
    }
})
